<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form" id="form_view_id">
</div>
</div>
    <script id="form_tpl_id" type="text/html">
        <input type="hidden" name="id" value="{{d.id}}" />

    <div class="layui-form-item">
        <label class="layui-form-label required">模板名称</label>
        <div class="layui-input-block">
            <input type="text" name="sms_tpl_name" lay-verify="required" lay-reqtext="模板名称不能为空" placeholder="请输入模板名称" class="layui-input" value="{{d.sms_tpl_name}}" >
            <tip>填写模板名称，用于内部备注。</tip>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label required">模板CODE</label>
        <div class="layui-input-block">
        	<input type="text" name="sms_tpl_code" lay-verify="required" lay-reqtext="请输入模板CODE" placeholder="请输入模板CODE" class="layui-input" value="{{d.sms_tpl_code}}" >
            <tip>第三方短信服务商提供的CODE，复制过来。例如阿里云短信模板CODE示例：SMS_211026000</tip>
        </div>
    </div>
    
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">模板KEY</label>
        <div class="layui-input-block">
        	{{=d.sms_tpl_key}}
        	<br />
        	<tip>内部技术开发使用，唯一标识</tip>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label required">模板内容</label>
        <div class="layui-input-block">
            <textarea name="sms_tpl_content" class="layui-textarea" placeholder="请输入模板内容">{{d.sms_tpl_content}}</textarea>
            <tip>在第三方短信服务商录入的模板内容，复制过来。</tip>
        </div>
    </div>
    
        
    <div class="layui-form-item">
        <label class="layui-form-label required">短信通道ID</label>
        <div class="layui-input-block">
            <input type="text" name="sms_supplier_id" lay-verify="required" lay-reqtext="短信通道ID不能为空" placeholder="请输入短信通道ID" value="{{d.sms_supplier_id}}" class="layui-input">
            <tip>填写短信通道ID，需要发送此短信的服务商。</tip>
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label required">模板类型</label>
        <div class="layui-input-block">
            <input type="radio" name="sms_tpl_type" value="1" title="验证码"  >
            <input type="radio" name="sms_tpl_type" value="2" title="短信通知" >
            <input type="radio" name="sms_tpl_type" value="3" title="推广短信" >
            <input type="radio" name="sms_tpl_type" value="0" title="其他" >
        </div>
    </div>
    

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
    </script>
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['laytpl', 'form'], function () {
        var form = layui.form,
            layer = layui.layer,
            router = layui.router(),
            laytpl = layui.laytpl,
            $ = layui.$;

        var id = sessionStorage.getItem('edit_id'); // router.search.id
        $.getJSON('/?s=Portal.Iadminossms_Tpl.GetData&id=' + id, function (data) {
            if (data.ret != 200 || !data.data.data) {
                layer.msg(data.msg || '数据不存在或已经删除');
            }

            var getTpl = form_tpl_id.innerHTML,
                view = document.getElementById('form_view_id');

            laytpl(getTpl).render(data.data.data, function(html){
                view.innerHTML = html;
                
                // 默认选中radio
				var sms_tpl_type = data.data.data.sms_tpl_type.toString();
				$.each($("input[name='sms_tpl_type']") ,function (index, d) {//index是索引,从0开始
					console.log(d.value,sms_tpl_type)
				 if( d.value === sms_tpl_type ) {
				   $(d).prop('checked', 'true');//选中
				   
				 }
			   })
		   
              	form.render('radio');
            });
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.ajax({
                url: '/?s=Portal.Iadminossms_Tpl.UpdateData',
                type:'post',
                data: {data: JSON.stringify(data.field), id: data.field.id},
                success:function(data){
                    if (data.ret != 200) {
                        layer.msg(data.msg);
                        return;
                    }

                    var index = layer.alert('更新成功，请刷新', function () {
                        // 关闭弹出层
                        layer.close(index);

                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);

                        //window.location.reload();
                    });
                },
                complete: function () {
                }
            });

            return false;
        });

    });
</script>
</body>
</html>
